package com.heatingcharge.controller.unit;


import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.HeatCompanyDTO;
import com.heatingcharge.param.HeatCompanyParam;
import com.heatingcharge.service.unit.IHeatCompanyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 热力分公司  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-07-12
 */
@RestController
@RequestMapping("/heat-company")
public class HeatCompanyController {

    @Autowired
    IHeatCompanyService heatCompanyService;

    @ApiOperation(value = "获取热力公司信息",notes = "获取热力公司信息")
    @GetMapping
//    @PreAuthorize("hasAuthority('sys:dept:view')")
    public R getHeatCompany(){
        List<HeatCompanyDTO> heatCompanyDtos = heatCompanyService.getHeatCopany();
        return R.ok(heatCompanyDtos);
    }

    @ApiOperation(value = "新增热力公司",notes = "新增热力公司")
    @PostMapping
    public R saveHeatCompany(@RequestBody HeatCompanyParam heatCompanyParam){
        if (heatCompanyService.save(heatCompanyParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "更新热力公司",notes = "更新热力公司")
    @PutMapping
    public R updateHeatCompany(@RequestBody HeatCompanyParam heatCompanyParam){
        if (heatCompanyService.update(heatCompanyParam)){
            return R.ok();
        }
        return R.error();
    }

    @ApiOperation(value = "删除热力公司",notes = "根据主键ID删除热力公司")
    @DeleteMapping("/{id}")
    public R delHeatCompany(@PathVariable("id") Integer id){
        if (heatCompanyService.removeById(id)){
            return R.ok();
        }
        return R.error();
    }
}

